package server.requesthandler;

import client.request.AllIdRequestMessage;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import server.response.AllIdResponseMessage;
import util.ChannelUtils;

import java.util.List;

/**
 * @Description 返回所有在线用户id
 * @author 14548
 */
public class AllIdRequestHandler extends SimpleChannelInboundHandler<AllIdRequestMessage> {

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, AllIdRequestMessage msg) throws Exception {
        System.out.println("收到所有id请求");
        Channel channel = ctx.channel();
        System.out.println(channel.remoteAddress() + ":客户端发来所有用户id请求");
        List<String> allId = ChannelUtils.getAllUserId();
        System.out.print("当前在线的用户为：");
        System.out.println(allId);
        channel.writeAndFlush(new AllIdResponseMessage(allId, allId.toString()));
    }
}
